package com.ja.openchat.ui.me;

import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ja.openchat.R;
import com.zy.openchat.core.model.user.SessionInfo;
import com.zy.openchat.util.TimeUtils;

public class LoginDeviceAdapter extends BaseQuickAdapter<SessionInfo, BaseViewHolder> {

    private boolean isInEditMode = false;

    public boolean isInEditMode() {
        return isInEditMode;
    }

    public void setInEditMode(boolean inEditMode) {
        isInEditMode = inEditMode;
        notifyDataSetChanged();
    }

    public LoginDeviceAdapter() {
        super(R.layout.item_login_device);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, SessionInfo sessionInfo) {
        ImageView device_icon = helper.getView(R.id.device_icon);
        if(isInEditMode){
            device_icon.setImageResource(R.drawable.ic_login_device_remove);
        }else{
            switch (sessionInfo.getPlatformType()){
                case SessionInfo.PC_FOR_WINDOWS:
                case SessionInfo.PC_FOR_MAC:
                    device_icon.setImageResource(R.drawable.login_device_for_pc);
                    break;
                case SessionInfo.WEB:
                    device_icon.setImageResource(R.drawable.login_device_for_web);
                    break;
                default:
                    device_icon.setImageResource(R.drawable.login_device_for_phone);
                    break;
            }
        }
        helper.setText(R.id.device_name,sessionInfo.device_model);
        helper.setText(R.id.app_name,String.format("%s %s",getContext().getString(R.string.app_name),sessionInfo.system_version));
        helper.setText(R.id.session_info,String.format("%s · %s",sessionInfo.country, TimeUtils.getMsgFormatTimeForYYMMDD(sessionInfo.last_active_date)));
    }
}
